
	/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR.dta"
	CREATES:	${out_tables}/T5A_rawchild_out.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}panel_RR_indexes.dta", clear


/*******************************************************************************
	Table A5: Raw child measures and indices of child outcomes. 
*******************************************************************************/
	* Rename relevant variables
	*---------------------------------



	local list "ibatt_rpi ibatt_rai raw_total_aud raw_total_exp"
	foreach var of local list {
	replace `var'=. if age_year>5 
	}
	replace ibatt_rsr=. if age_year==8

	gen cbcl_int_desc= ach_rint
	replace cbcl_int_desc= cbcl2_rs_i if age_year>=6
	gen cbcl_ext_desc= ach_rext
	replace cbcl_ext_desc= cbcl2_rs_e if age_year>=6
	label define years 3 "3-4" 4 "4-5" 5 "5-6" 6 "6-7" 7 "7-8" 8 ">8"
	label values age_year years

	label var ptevir_raw_score2 "TEVI-R"
	label var dccspunt "DCCS"
	label var as_raw_score "Sustained attention"
	label var ibatt_rpi "Battelle - Peers interaction"
	label var ibatt_rai "Battelle - Adults interaction"
	label var ibatt_rsr "Battelle - Social role"
	label var cbcl_int_desc "CBCL - external"
	label var cbcl_ext_desc "CBCL - internal"


	xtset CENTRO_SALUD

	tabstat ptevir_raw_score2 dccspunt as_raw_score ibatt_rpi ibatt_rai ibatt_rsr cbcl_int_desc cbcl_ext_desc, by(age_year) s(mean N) save
	forvalues i = 1(1)6{
		
		matrix stat`i' = r(Stat`i')

	}
		matrix stat7 = r(StatTotal)

	putexcel set "${out_tables}/appendix/T5A_rawchild_out.xls", replace sheet("Table5A")

	putexcel (A1:D1), bold border(bottom)
	putexcel A1  =  "Table A5: Raw child measures and indices of child outcomes"
	putexcel A3  =  "Age at endline"
	putexcel A4  =  "3-4"
	putexcel A6  =  "4-5"
	putexcel A8  =  "5-6"
	putexcel A10  =  "6-7"
	putexcel A12  =  "7-8"
	putexcel A14  =  ">8"
	putexcel A16  =  "Total"
	
	local i = 4
	local m = 1
	while `i'  <17{
		local j= `i' + 1
		putexcel A`i'  =  "mean"
		putexcel A`j'  =  "N"
		putexcel C`i'  =  matrix(stat`m')

		local i = `i' + 2
		local m = `m' + 1

	}

	putexcel B3  =  "Stat"
	putexcel C3  =  "TEVI-R"
	putexcel D3  =  "DCCS"
	putexcel E3  =  "Sustained attention"
	putexcel F3  =  "Battelle - Peers interaction"
	putexcel G3  =  "Battelle - Adults interaction"
	putexcel H3  =  "Battelle - Social role"
	putexcel I3  =  "CBCL - external"
	putexcel J3  =  "CBCL - internal"
